import { createRouter, createWebHashHistory } from 'vue-router'
import routerMap from './routerMap'
import { getRandomString } from '../utils/common'

const Router = createRouter({
  history: createWebHashHistory(),
  routes: routerMap
})

Router.beforeEach((to, from, next) => {
  if (!window.localStorage.getItem('__session__')) {
    const str = getRandomString(16)
    window.localStorage.setItem('__session__', str)
  }
  next()
})

export default Router
